#Computing the degree for the sample restricted to articles that includes gender for all authors#

library(igraph)
source("getntwrks6auth.R")
data<-read.csv("networkgender_restsample7017.csv",header=TRUE)
names(data)
colnames(data) <- c("articleid", "auth1", "gender1", "auth2", "gender2","auth3","gender3","auth4","gender4","auth5","gender5","auth6","gender6","nauthors","year","journalid","prod") 
# endyears and length to compute networks
ks <- 5
for (k in ks) {
 endyears <- (1970+k-1):2017
  for (endyear in endyears) {
    startyear <- endyear - k+1
    y <- subset(data,year>=startyear & year<=endyear)
    g <- getnetwork(startyear,endyear, data)
    y$auth6[is.na(y$auth6)]<--5 
    y$auth5[is.na(y$auth5)]<--4 
    y$auth4[is.na(y$auth4)]<--3 
    y$auth3[is.na(y$auth3)]<--2 
    y$auth2[is.na(y$auth2)]<--1  
    V(g)$deg <- degree(g)
    V(g)$auth<-V(g)
    d<-data.frame(V(g)$auth,V(g)$deg)
    write.csv(d,file=paste("deg", endyear, "_", k, "y.csv", sep=""),na=".")
  }
}
